package com.github.zzay.common.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @author zzay
 * @className CorsConfig
 * @description Configuration class for handling CORS
 * @create 2022/07/06 23:07
 */
@Configuration
public class CorsConfig implements WebMvcConfigurer {

    // Allowed methods
    private static final String[] ALLOWED_METHODS = new String[]{
            "GET", "POST", "PUT", "DELETE"
    };

    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**")
                .allowedOrigins("*")
                .allowCredentials(true)
                .allowedMethods(ALLOWED_METHODS)
                .allowedHeaders("*")
                .maxAge(3600);
    }

}
